﻿-- Creating table 'ProductTrackings'
CREATE TABLE [dbo].[ProductTrackings] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Action] varchar(1)  NOT NULL,
    [Unit] float  NOT NULL,
    [CreateOn] datetime  NOT NULL,
    [DeleteOn] datetime  NULL,
    [ProductId] int  NOT NULL,
    [ProductPricingPerUnitId] int  NOT NULL,
    [MemberId] int  NOT NULL
);
GO
-- Creating foreign key on [ProductId] in table 'ProductTrackings'
ALTER TABLE [dbo].[ProductTrackings]
ADD CONSTRAINT [FK_ProductProductTracking]
    FOREIGN KEY ([ProductId])
    REFERENCES [dbo].[Products]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO
-- Creating foreign key on [ProductPricingPerUnitId] in table 'ProductTrackings'
ALTER TABLE [dbo].[ProductTrackings]
ADD CONSTRAINT [FK_ProductPricingPerUnitProductTracking]
    FOREIGN KEY ([ProductPricingPerUnitId])
    REFERENCES [dbo].[ProductPricingPerUnits]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO
-- Creating foreign key on [MemberId] in table 'ProductTrackings'
ALTER TABLE [dbo].[ProductTrackings]
ADD CONSTRAINT [FK_MemberProductTracking]
    FOREIGN KEY ([MemberId])
    REFERENCES [dbo].[Members]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO
-- Creating primary key on [Id] in table 'ProductTrackings'
ALTER TABLE [dbo].[ProductTrackings]
ADD CONSTRAINT [PK_ProductTrackings]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO
-- Creating non-clustered index for FOREIGN KEY 'FK_ProductProductTracking'
CREATE INDEX [IX_FK_ProductProductTracking]
ON [dbo].[ProductTrackings]
    ([ProductId]);
GO
-- Creating non-clustered index for FOREIGN KEY 'FK_ProductPricingPerUnitProductTracking'
CREATE INDEX [IX_FK_ProductPricingPerUnitProductTracking]
ON [dbo].[ProductTrackings]
    ([ProductPricingPerUnitId]);
GO
-- Creating non-clustered index for FOREIGN KEY 'FK_MemberProductTracking'
CREATE INDEX [IX_FK_MemberProductTracking]
ON [dbo].[ProductTrackings]
    ([MemberId]);